#!/bin/csh

# Kill process at using port 50001
kill `lsof -i :50001 | tail -n +2 | sed -e 's,[ \t][ \t]*, ,g' | cut -f2 -d' '`
kill `lsof -i :50002 | tail -n +2 | sed -e 's,[ \t][ \t]*, ,g' | cut -f2 -d' '`
kill `lsof -i :50003 | tail -n +2 | sed -e 's,[ \t][ \t]*, ,g' | cut -f2 -d' '`
kill `lsof -i :50004 | tail -n +2 | sed -e 's,[ \t][ \t]*, ,g' | cut -f2 -d' '`

# Remove previous output
rm *.out
rm *.stat

# arg1 is file size
# arg2 is file name
set FILENAME=$argv[2]
./generator $argv[1] $FILENAME

relayer/relayer relayer/config.xml >& relayer.log &
sleep 1
# Default window size 200
reliable/reliable -r 1.out -w 200 20000 linux23:50002 >& recv1.log &
reliable/reliable -r 2.out -w 200 40000 linux23:50004 >& recv2.log &

reliable/reliable -s $FILENAME 10000 linux23:50001 >& sender1.log &
reliable/reliable -s $FILENAME 30000 linux23:50003 >& sender2.log &
